/**
 * 配置模块
 */

// API基础URL - 可以从URL参数获取，或直接配置
export const API_BASE_URL = (() => {
  // const urlParams = new URLSearchParams(window.location.search);
  // return urlParams.get('apiUrl') || window.location.origin;
  return 'https://anfine.huasun-healthcare.com/api-ah'
})();

// 默认PID
export const DEFAULT_PID = '1950460485593350145';

// 默认医院ID
export const DEFAULT_HOSPITAL_ID = '1';

/**
 * 获取组织ID的函数（如果需要）
 */
export const getOrgId = async () => {
  try {
    const orgCode = new URLSearchParams(window.location.search).get('orgCode') || '';
    if (!orgCode) {
      console.warn('orgCode is empty, using default value');
      return '0';
    }
    
    const response = await fetch(`${API_BASE_URL}/sys/sysDepart/getDepartName?orgCode=${orgCode}`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
      credentials: 'include'
    });
    
    const res = await response.json();
    console.log('getOrgId res===', res);
    if (res.result && res.result.id) {
      return res.result.id;
    }
  } catch (error) {
    console.error('获取组织ID失败:', error);
  }
  return '0';
};

